package com.noodles.mall.exception;

import com.noodles.mall.web.JsonResult;
import com.noodles.mall.web.State;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler extends RuntimeException {

    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(value = RuntimeException.class)
    public JsonResult exceptionHandler(Exception e) {
        System.out.println("GlobalExceptionHandler: exceptionHandler");
        logger.error("GlobalExceptionHandler: {}", e.getMessage());
        e.printStackTrace();
        return JsonResult.error(State.ERR_SYS,e.getMessage());
    }
}


